package com.oa.ylms.apps.actions.goods;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts2.interceptor.ServletResponseAware;

import com.oa.ylms.apps.business.goods.IGoodsCategoryService;
import com.oa.ylms.apps.constants.goods.IGoodsInfoStates;
import com.oa.ylms.apps.entity.goods.GoodCategoryValue;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GoodsCategoryAction extends ActionSupport implements
		ServletResponseAware {
	private IGoodsCategoryService service;
	private List<GoodCategoryValue> list;
	private HttpServletResponse response;
	private String str;
	private Integer categoryId;
	private String categoryName;
	private Integer states;
	private String categoryIds;
	public String execute() {
		try {
			list = service.queryAll(IGoodsInfoStates.NOTBYSTATES);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "show";
	}

	public String modify() {
		try {
			
			service.modifyGoodsCategory(categoryId,categoryName,0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "modify";
	}

	public String delete() {
		try {
			System.out.println("categoryId:"+categoryId);
			service.deleteGoodsCategory(categoryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "delete";
	}
	public String deleteMore(){
		try {
			service.deleteGoodsCategorys(categoryIds);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "deleteMore";
	}

	public String add() {
		try {
			service.addGoodsCategory(categoryName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "add";
	}

public String toEnable(){
	try {
		service.toEnable(categoryId);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return "toEnable";
}
public String toDisable(){
	try {
		service.toDisable(categoryId);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return "toDisable";
}
	public String getAllCategory() {
		try {
			list = service.queryAll(IGoodsInfoStates.NOTBYSTATES);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		JSONArray obj = JSONArray.fromObject(list);
		this.str = obj.toString();
		response.setContentType("text/html; charset=gb2312");
		response.setHeader("Cache-Control", "no-cache");
		try {
			response.getWriter().print(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		
	}

	public IGoodsCategoryService getService() {
		return service;
	}

	public void setService(IGoodsCategoryService service) {
		this.service = service;
	}

	public List<GoodCategoryValue> getList() {
		return list;
	}

	public void setList(List<GoodCategoryValue> list) {
		this.list = list;
	}

	public String getCategoryIds() {
		return categoryIds;
	}

	public void setCategoryIds(String categoryIds) {
		this.categoryIds = categoryIds;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}

	

	public Integer getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Integer categoryId) {
		this.categoryId = categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public Integer getStates() {
		return states;
	}

	public void setStates(Integer states) {
		this.states = states;
	}

	
	
}
